<style lang="scss" scoped>
  @import '../../styles/common/loading.less';
  .container{
    border: none !important;
    margin-top: 4px;
  }
  .el-col-offset-1 {
    margin-left: 0%;
  }
  .button_a {
    background-color: rgba(255, 138, 0, 1);
    border-color: rgba(255, 138, 0, 1);

  }
  .col_a {
    margin-left: 2%;
  }
  .el-card {
    height: 200px;
  }

  .el-button--primary {
    background-color: rgba(255, 138, 0, 1);
    border-color: rgba(255, 138, 0, 1);
  }
</style>
<template>
  <div>
    <div class="container" >
      <el-form :model="formInline" class="select-submit-form">
        <el-row type="flex">
          <el-col :span="8" :offset="2">
            <el-form-item label="统筹区名称">
              <el-input v-model="formInline.overallName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="select-btn-group">
              <el-button type="primary" size="medium"  @click="onSubmitYbjgxxgl">查询</el-button>
              <el-button type="primary" size="medium" @click="handleReset">重置</el-button>
              <el-button type="primary" size="medium" @click="save()" >增加</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        :data="tableData"
        class="table"
        ref="multipleTable"
        header-cell-class-name="table-header"
        style="margin-top: 20px"
      >
<!--        <el-table-column type="selection" width="55" align="center"></el-table-column>-->
<!--        <el-table-column prop="comName" label="归属机构" align="center"></el-table-column>-->
        <el-table-column prop="overallName" label="统筹区名称" align="center"></el-table-column>
        <!--<el-table-column prop="handler" label="经办人" align="center"></el-table-column>
        <el-table-column prop="handlTime" label="经办时间" align="center"></el-table-column>-->
        <el-table-column prop="creater" label="创建人" align="center"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="handleLook(scope.$index, scope.row)">查看</el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleEdit(scope.$index, scope.row)">修改</el-button>
            <el-button
              size="mini"
              type="text"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination" v-if="this.tableData.length!==0">
        <div class="index_page">
          <el-pagination :current-page="pagination.currentPage" :page-size="pagination.rowsNumber"
                         :page-sizes="[10, 20, 50, 100]"
                         :total="pagination.totalPage" background layout="prev, pager, next,sizes,total,jumper"
                         @size-change="handleSizeChange" @current-change="queryFun">
          </el-pagination>
        </div>
      </div>
  </div>
  </div>
</template>
<script>
  import * as api from '@/api/basicInformation'
  export default {
    name: 'baseform',
    inject:['reload'],
    data() {
      return {
        pagination: {
          currentPage: 1, // 当前页
          rowsNumber: 10, // 每页条数
          totalPage: 12 // 总条数
        },
        item:0,
        formInline:{},
        query: {
          address: '',
          name: '',
          pageIndex: 1,
          pageSize: 10
        },
        checkList: ['急诊'],
        props: { multiple: true },
        dialogFormVisible: false,
        tableData:[
        ],
        options: [{
          value: 1,
          label: '东南',
          children: [{
            value: 2,
            label: '上海',
            children: [
              { value: 3, label: '普陀' },
              { value: 4, label: '黄埔' },
              { value: 5, label: '徐汇' }
            ]
          }, {
            value: 7,
            label: '江苏',
            children: [
              { value: 8, label: '南京' },
              { value: 9, label: '苏州' },
              { value: 10, label: '无锡' }
            ]
          }, {
            value: 12,
            label: '浙江',
            children: [
              { value: 13, label: '杭州' },
              { value: 14, label: '宁波' },
              { value: 15, label: '嘉兴' }
            ]
          }]
        }, {
          value: 17,
          label: '西北',
          children: [{
            value: 18,
            label: '陕西',
            children: [
              { value: 19, label: '西安' },
              { value: 20, label: '延安' }
            ]
          }, {
            value: 21,
            label: '新疆维吾尔族自治区',
            children: [
              { value: 22, label: '乌鲁木齐' },
              { value: 23, label: '克拉玛依' }
            ]
          }]
        }],
        drugCatalog:[
          {comCode: "20000000000",comName:"总公司"},
          {comCode: "20020000000",comName:"江苏分公司"},
          {comCode: "20020100000",comName:"徐州中支公司"},
        ],
        form: {
        },
        handleInstitutionWholeDemo:{},
      };
    },
    mounted() {
      this.restaurants=this.drugCatalog.map(item=>{
        return{
          code:item.comCode,
          value:item.comName,
        }
      })
    },
    created() {
      debugger
      api.getQueryOverallPlanList({
        "head": {},
        "body": {
          "pageNum":this.pagination.currentPage,
          "pageSize":this.pagination.rowsNumber,
        }
      }).then(res => {
        console.log(res)
        this.tableData=res.data.list;
        this.pagination.totalPage=res.data.total;
      })
    },
    methods: {
      handleSizeChange(pageSize){ // 改变当前页条数事件
        this.pagination.rowsNumber=pageSize
        this.onSubmitYbjgxxgl();
        /* let pageIndex = this.pagination.currentPage;
         this.querySettleAuditTaskList(pageIndex,pageSize);*/
      },
      queryFun(pageNum){ // 改变当前页事件
        this.pagination.currentPage=pageNum
        this.onSubmitYbjgxxgl();
        /* let rowsNumber = this.pagination.rowsNumber;
         this.querySettleAuditTaskList(pageNum,rowsNumber);*/
      },
      querySearchAsync(queryString, cb) {
        var restaurants = this.restaurants;
        var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

        clearTimeout(this.timeout);
        this.timeout = setTimeout(() => {
          cb(results);
        }, 1000 * Math.random());
      },
      createStateFilter(queryString) {
        return (state) => {
          // return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
          return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
        };
      },
      // 重置
      handleReset(){

      },
      // 添加
      save(){
        this.$router.push({
          name: 'handleInstitutionWholeDemo',
          query: {
            handleInstitutionWholeDemo: JSON.stringify(this.handleInstitutionWholeDemo),
            item: JSON.stringify(0),
          }
        })
      },
      // 查询
      onSubmitYbjgxxgl(){
        var data = {
          "comName":this.formInline.comName,
          "overallName":this.formInline.overallName,
          "pageNum":this.pagination.currentPage,
          "pageSize":this.pagination.rowsNumber,
        }
        api.getQueryOverallPlan(data
        ).then(res => {
          this.tableData =res.data.list;
          this.pagination.totalPage=res.data.total;
          if(res.data.resultCode){
            if(res.data.resultCode !== '0000'){
              this.$message.error(res.data.resultMsg);
            }else{
              this.$message.success(res.data.resultMsg);
            }
          }else{

            this.pagination.totalPage = res.data.total;
          }
        })
      },
      // 查看
      handleLook(index,row) {
        this.handleInstitutionWholeDemo = row,
          this.$router.push({
            name: 'handleInstitutionWholeDemo',
            query: {
              handleInstitutionWholeDemo: JSON.stringify(this.handleInstitutionWholeDemo),
              item: JSON.stringify(2),
            }
          })
      },
      // 修改
      handleEdit(index,rew){
        this.handleInstitutionWholeDemo=rew,
          this.$router.push({
            name: 'handleInstitutionWholeDemo',
            query: {
              handleInstitutionWholeDemo: JSON.stringify(this.handleInstitutionWholeDemo),
              item: JSON.stringify(1),
            }
          })
      },

      // 删除
      handleDelete(index,rew){
        var data={
          "id":rew.id,
        }
        api.getDeleteOverallPlan(data
        ).then(res => {
          if(res.data.resultCode){
            if(res.data.resultCode !== '0000'){
              this.$message.error(res.data.resultMsg);
            }else{
              this.$message.success(res.data.resultMsg);
            }
          }
          this.reload();
        })
      },
      onSubmit() {
        this.$message.success('提交成功！');
      },
      // 分页导航
      handlePageChange(val) {
        this.$set(this.query, 'pageIndex', val);
        this.getData();
      },
    }
  };
</script>